﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MayhemWpf.UserControls;
using SensorMayhem.Helpers;
using SensorMayhem.Events;

namespace SensorMayhem.Wpf
{
    /// <summary>
    /// Interaction logic for OrientationConfig.xaml
    /// </summary>
    public partial class OrientationConfig : WpfConfiguration
    {

        public OrientationConfig(OrientationType orientation)
        {
            InitializeComponent();

            this.OrientationComboBox.Items.Add(OrientationTypes.LayingUpsideUp);
            this.OrientationComboBox.Items.Add(OrientationTypes.LayingUpsideDown);
            this.OrientationComboBox.Items.Add(OrientationTypes.Landscape);
            this.OrientationComboBox.Items.Add(OrientationTypes.Portrait);

            var sItem = (from object item in this.OrientationComboBox.Items
                        where String.Compare(item.ToString(), orientation.ToString()) == 0
                        select item).FirstOrDefault();

            Orientation = orientation;

            this.OrientationComboBox.SelectedIndex = this.OrientationComboBox.Items.IndexOf(sItem);

            CanSave = true;
        }

        public override string Title
        {
            get
            {
                return "Orientation detection";
            }
        }

        public OrientationType Orientation
        {
            get;
            set;
        }

        public override void OnLoad()
        {
            var sItem = (from object item in this.OrientationComboBox.Items
                        where String.Compare(item.ToString(), Orientation.ToString()) == 0
                        select item).FirstOrDefault();

            this.OrientationComboBox.SelectedIndex = this.OrientationComboBox.Items.IndexOf(sItem);
        }

        public override void OnSave()
        {
            Orientation = (OrientationType)this.OrientationComboBox.SelectedValue;
        }

    }
}
